<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>计划执行-计划调整详情页面</title>
    <script src="/scripts/boot.js"></script>
    <link href="/scripts/daterangepicker/js/daterangepicker.min.css" rel="stylesheet" type="text/css" />
    <script src="/scripts/daterangepicker/js/moment.js" type="text/javascript"></script>
    <script src="/scripts/daterangepicker/js/jquery.daterangepicker.min.js" type="text/javascript"></script>
    <script src="/scripts/daterangepicker/ux.daterangepicker.js" type="text/javascript"></script>
    <link href="/scripts/daterangepicker/css/skin.css" rel="stylesheet" type="text/css" />
    <!--//上传插件-->
    <link href="/scripts/webuploader/css/webuploader.css" rel="stylesheet" type="text/css" />
    <link href="/scripts/webuploader/css/style.css" rel="stylesheet" type="text/css" />
    <script src="/scripts/webuploader/js/webuploader.js"></script>
    <script src="/scripts/webuploader/js/upload.js"></script>
    <style>
        html body .searchbox .mini-buttonedit-icon
        {
            /*background:url(static/scripts/daterangepicker/search.gif) no-repeat 50% 50%;*/
        }
        .rangeHidden{
            display: none;
        }
    </style>
</head>

<body class="bg-white">
<div id="editForm">
    <div class="title-info mb-20"><span>计划信息</span></div>
    <table class="editTable table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="150px"></col>
            <col width="50%"></col>
            <col width="150px"></col>
            <col width="50%"></col>
        </colgroup>
        
        <tr>
            <td class="text-titlebg">
                所属项目
            </td>
            <td >
                <input type="text" id="itemName"  name="itemName" enabled="false" class="mini-textbox w250" required="true"  vtype="maxLength:48"   errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"/>
            </td>
            <td class="text-titlebg">
                项目计划
            </td>
            <td >
                <input type="text" id="planName"  name="planName" class="mini-textbox w250" enabled="false" required="true"  vtype="maxLength:48"   errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"/>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg">
                所属类别
            </td>
            <td  >
                <input type="text" id="planTypeName"  name="planTypeName" enabled="false" class="mini-textbox w250" required="true"  vtype="maxLength:48"   errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"/>
            </td>
            <td class="text-titlebg">
                所属计划节点
            </td>
            <td  >
                <input type="text" name="nodeName" enabled="false" class="mini-textbox w250" required="true"  vtype="maxLength:48"   errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"/>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg">计划起止时间
            </td>
            <td>
                <input id="date-range1" class="uc-daterangepicker searchbox w250" enabled="false"/>
			    <input name="id" id="planNodeId" class="mini-hidden"/>
            </td>

            <td class="text-titlebg">
                <span class="color-red">*</span>实际结束日期
            </td>
            <td>
                <input type="text" id="overDate"  name="overDate" class="mini-datepicker w250" allowInput="false" required="true"  vtype="maxLength:48"   errorMode="none" onvalidation="onChoseValidation" requiredErrorText="请选择日期"/>
            </td>
        </tr>
    </table>
    <div class="title-info"><span>详细信息</span>
        <div class="position-rel">
            <div class="position-abs">
                <a onclick="view.addRow()" class="newly">新增</a>
                <a class="delAll" onclick="view.removeRow()">删除</a>
            </div>
        </div>
    </div>

    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:280px; margin-top: 35px;" idField="id" url="/monthlyPlanExecution/fruitArchivesDetailedListByPage"
         allowResize="true" pageSize="20" allowCellEdit="true" allowCellSelect="true" multiSelect="true"  editNextOnEnterKey="true"  editNextRowCell="true">
        <div property="columns">
            <div type="checkcolumn" allowResize="false" width="15"></div>
            <div type="indexcolumn" allowResize="false" width="15">编号</div>
            <div   field="id" name="id" hidden="true"  headerAlign="center" allowSort="true" allowResize="false">
                <input property="editor"   class="mini-hidden" style="width:100%;" minWidth="200" />
            </div>
            <div   field="achievementName" name="achievementName" headerAlign="center" allowSort="true" width="80" allowResize="false">成果名称
                <input property="editor"   class="mini-textbox" style="width:100%;" minWidth="200" />
            </div>
            <div field="achievementNature" displayField="achievementNature_value" name="achievementNature"  width="80" headerAlign="center" allowSort="true" allowResize="false">成果性质
                <!--<input property="editor" class="mini-combobox" url="/dictionary/listValues?name=achievementNature"  textField="value" valueField="id" />-->
                <input property="editor" class="mini-combobox" url="/dictionary/listValues?name=achievementNature"  textField="value" valueField="id" />
            </div>
            <div field="achievementTime"  name="achievementTime" renderer="view.ondayRenderer" headerAlign="center"  width="40" allowSort="true" allowResize="false">成果取得时间
                <input property="editor" class="mini-datepicker"  minValue="0" maxValue="200" value="25" style="width:100%;"/>
            </div>
            <div field="patternManifestation" displayField="patternManifestation_value" name="patternManifestation" width="50" allowSort="true" allowResize="false">表现形式
                <input property="editor" class="mini-combobox"  url="/dictionary/listValues?name=patternManifestation"  textField="value" valueField="id" />
            </div>
            <div field="storagePlace"  name="storagePlace" width="50" allowSort="true" allowResize="false">原始资料存放位置
                <input property="editor" class="mini-textbox"  minValue="0" maxValue="200" value="25" style="width:100%;"/>
            </div>
            <div   field="file_url" name="file_url" hidden="true"  headerAlign="center" allowSort="true" allowResize="false">
                <input property="editor" class="mini-hidden" style="width:100%;" minWidth="200" />
            </div>
            <div field="file_name" name="file_name" renderer="view.getFile"  headerAlign="center" allowSort="true" allowResize="false">已上传文件

            </div>
            <div field="" name="action" renderer="view.onActionRenderer" headerAlign="center"  width="45" allowSort="true"allowResize="false" >操作

            </div>

        </div>
    </div>
    <div class="chose-toolbar">
        <div id="uploader" class="webuploader-container" style="display:none;"></div>
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save()">提交</a>
    </div>
</div>
<script src="/scripts/res/js/common.js"></script>
<script type="text/javascript">
    var grid,form,i ,idsss;
    //用于存储附件名
    var newData=[];
    var json;
    var view = {
        init:function () {
            mini.parse();
            grid = mini.get("datagrid1");
            form = new mini.Form("#editForm");
            //grid.load();
            grid.hideColumn("id");//隐藏列
            grid.hideColumn("file_url");//隐藏列
            grid.on("celleditenter", function(e) {
                var index = grid.indexOf(e.record);
                if (index == grid.getData().length - 1) {
                    var row = {};
                    grid.addRow(row);
                }
            });
        },
        //格式化日期
        ondayRenderer: function(e) {
            if (e.value) {
                var value = new Date(e.value);
                if (value) {
                    return mini.formatDate(value, 'yyyy-MM-dd')
                }
            }else{
                return "";
            }
        },
        //添加行
        addRow: function() {
            var newRow = {
                name : "New Row"
            };
            grid.addRow(newRow, 0);

            grid.beginEditCell(newRow, "LoginName");
        },
        //移除行
        removeRow: function() {
            var rows = grid.getSelecteds();

            if (rows.length > 0) {
                var ids = [];
                for (var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    if(r.id){
                        ids.push(r.id);
                    }
                }

                idsss = ids.join(',');

            } else {
                alert("请选中一条记录");
            }
            if (rows.length > 0) {
                grid.removeRows(rows, true);
            }

        },
        //回显数据
        SetData:function (data) {
            data = mini.clone(data);
            mini.get("planNodeId").setValue(data.id);
            i = data.id;
            //跨页面传递的数据对象，克隆后才可以安全使用
            $.ajax({
                url:"/monthlyPlanExecution/info?id=" + data.id,
                type: "post",
                success: function (text) {
                    var obj = JSON.parse(text);
                    //跨页面传递的数据对象，克隆后才可以安全使用
                    datas = mini.decode(obj.body[0]);   //反序列化成对象
                    form.setData(datas);             //设置多个控件数据
                    mini.get("date-range1").setValue(datas.beginDate +" ~ " +datas.endDate)
                }
            });
        },
        //设置信息
         onActionRenderer: function(e){
             var s ='<a class="update-button" onclick="view.aaaa()"></a>';
             return s;
         },
         //点击上传按钮
         aaaa: function(){
            $('.webuploader-element-invisible').trigger('click');
         },
         getFile: function(e){
            var list = e.row.listFile;
            var v="<div><sapn id='span_id"+e.row._id+"'></span></div>";
            if(list){
                for(var i=0;i<list.length;i++){
                    var file = list[i];
                    var fileName = file.file_name;
                    var fileUrl = file.file_url;
                    var fileid =	file.id;
                    var a= "<div id='"+fileid+"' class='file-box'>"+
                        "<a class='file-name' href='javascript:void(0)' onclick=\"view.downFile('" +fileUrl+"','"+fileName+"')\">"+fileName+"</a>"+
                        "<span class='img-wh' onclick=\"view.delFile('" +fileid+"','"+fileUrl+"')\"></span>"+
                        "</div><br/>";
                    v+=a;
                }
            }
            return v;
         },
         //保存
         save: function(){
            var ddddd=newData;
            form.validate();
            if (form.isValid() == false) return;
            var data1 = form.getData();      //获取表单多个控件的数据
            var infoss = grid.data;
            for(var m=0;m<ddddd.length;m++){

                var fileuu = ddddd[m];
                var u_id = fileuu.split(":");

                for(var n=0;n<infoss.length;n++){
                    var filess = infoss[n];
                    var _id = filess._id;
                    if(u_id[0]==_id){
                        infoss[n].file_name=u_id[1];
                        break;
                    }
                }

            }
            var arr = [];
            for(f in infoss){
                var info = infoss[f]
                var achievementName =  info.achievementName;
                if(achievementName){
                    var achievementName =  info.achievementName;
                    var  achievementNature =  info.achievementNature;
                    var achievementTime  =  info.achievementTime;
                    var  patternManifestation =  info.patternManifestation;
                    var  storagePlace =  info.storagePlace;
                    var  fileUrl =  info.file_url;
                    var  fileName =  info.file_name;
                    var  id =  info.id;

                    var m={
                        "achievementName":achievementName,
                        "achievementNatureId":achievementNature,
                        "achievementTime":achievementTime,
                        "fileUrl":fileUrl,
                        "fileName":fileName,
                        "patternManifestationId":patternManifestation,
                        "storagePlace":storagePlace
                    }
                    if(id){
                        m.id=id;
                    }
                    arr.push(m);
                }
            }
            var d = {};
            d.detailinfos=arr;
            d.planNode=data1;
            var info = JSON.stringify(d);

            $.ajax({
                type : "post",
                url : "/monthlyPlanExecution/saveKeyFruitArchives",
                data : {"data":info},
                success : function(msg) {
                    CloseWindow("ok")
                }
            });
            if(idsss){
                view.delAll(idsss);
            }
         },
         //审核
         audit:function () {
     		var row = grid.getSelected();
            $.ajax({
 				type : "post",
 				url : "/loggerService/startPost",
 				data : {"id":row.id,"formSign":"CDJHGLJHZXCGTB_01","workFlowId":"CDJHGLJHZXCGTBSP","jumpUrl":"/program/monthlyPlan/workflow.html?id="+pid,"url":"/act/taskApi/start","exampleEntity":"planNodeAdjust"},
 				success : function(msg) {
 					if(msg.message==="ok"){
 						view.updateAuditState(row.id);
 					}
 				}
 			}); 
         } ,
         delAll:function(idsss){
            $.ajax({
                url: "/settlement/plan/info/datum/delAll?id="+idsss,
                success: function (text) {
                    grid.reload();
                },
                error: function () {
                }
            });

         },
         setFile_url: function(url,num){
            var row = grid.getSelected ();
            var old_url= row.file_url;

            if(!old_url){
                grid.updateRow(row,{file_url:url})
            }else{
                if(old_url!=""){
                    old_url=old_url+";  "
                }
                var value = old_url+url;

                grid.updateRow(row,{file_url:value})
            }
         },
         setFile_name: function(name, num) {
            var row = grid.getSelected();
            var rowId = row._id;
            var leth = newData.length;
            if(leth>0){
                var d ;
                var m=0;
                for(var i=0;i<newData.length;i++){

                    d = newData[i];
                    var aa = d.split(":");
                    var aaa = aa[0];
                    if(aaa==rowId){
                        d=d+";  "+name;
                        newData[i] = d;

                        var bb = d.split(":");
                        var value = bb[1];
                        $("#span_id"+row._id).append(value);
                        break;
                    }else{
                        m++;
                    }
                }
                if(m==newData.length){
                    var a = rowId+":"+name;
                    newData.push(a);
                    $("#span_id"+row._id).append(name);
                }
            }else{
                var a = rowId+":"+name;
                newData.push(a);
                $("#span_id"+row._id).append(name);
            }
         },
         downFile: function(url, name) {
            window.location.href = "/ftp/downFile?path=" + url
                + "&fileName=" + name;
         },
         delFile: function(fid, url) {
            $.ajax({
                type : "post",
                url : "/file/del?id=" + fid + "&file_url=" + url,
                success : function(msg) {
                    if (msg.state) {
                        $('#' + fid).remove();
                    }
                }
            });
         }
    };
    view.init();
</script>
</body>
</html>